package com.ayuan.blog.common.util;

import org.apache.commons.lang.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by xiaozhu on 16/8/14.
 */
public class CookieUtils {

    public static Cookie getCookie(HttpServletRequest request, String key) {
        Cookie[] cookies = request.getCookies();
        if (ArrayUtils.isNotEmpty(cookies) && org.apache.commons.lang.StringUtils.isNotEmpty(key)) {
            for (Cookie cookie : cookies) {
                if (key.equals(cookie.getName())) {
                    return cookie;
                }
            }
        }
        return null;
    }
}
